import Taro, {Component} from '@tarojs/taro'
import { Text, View } from '@tarojs/components'
import { filterStyles } from "@/utils/filter"
import classNames from 'classnames'
import './index.scss'

//  获取数字
const getNum = function (price=0) {
  return price.toString().split('.')
}

interface IProps {
  color?: string
  price: number
  isNumber?: boolean
  unitSize?: number
  priceSize?: number
  decimalSize?: number
  className?: string
}

export default class SalePrice extends Component<IProps, {}> {
  props: any

  static options = {
    addGlobalClass: true
  }

  render() {
    const prefixCls = 'sale-price'
    const { color, price, isNumber, unitSize=20, priceSize=32, decimalSize=20, className } = this.props
    const arr = getNum(isNumber ? Number(price) : price)
    return (<View className={classNames(`${prefixCls} bnn-price`, className)} style={filterStyles({ color: color })}>
      <Text className={`${prefixCls}__prefix f-s-${unitSize}`}>￥</Text>
      <Text className={`${prefixCls}__text f-s-${priceSize}`}>{arr[0]}</Text>
      {arr[1] && <Text className={`${prefixCls}__suffix f-s-${decimalSize}`}>.{arr[1]}</Text>}
    </View>)
  }
}
